#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define LEN 81

char *s_gets(char *str, int n);
char showmenu(void);
void eatline(void); //读取到行末尾
void show(void (*fp)(char *), char *str);
void ToUpper(char *);   //把字符串转换成大写
void ToLower(char *);   //把字符串转换成小写
void Transpose(char *); //大小写转制
void Dummy(char *);     //不更改字符串

int main(int argc, char const *argv[])
{
    char line[LEN];
    char copy[LEN];
    char choice;
    //声明一个函数指针
    void (*pfun)(char *);

    puts("Enter a string (empty to quit):");
    while (s_gets(line, LEN) != NULL && line[0] != '\0')
    {
        while ((choice = showmenu()) != 'n')
        {
            switch (choice)
            {
            case 'u':
                pfun = ToUpper;
                break;
            case 'l':
                pfun = ToLower;
                break;
            case 't':
                pfun = Transpose;
                break;
            case 'o':
                pfun = Dummy;
                break;

                strcpy(copy, line);
                show(pfun, copy);
            }
        }
    }
    puts("Bye!");

    return 0;
}

char *s_gets(char *str, int n)
{
    char *ret_val;
    char *find;
    ret_val = fgets(str, n, stdin);
    if (ret_val)
    {
        find = strchr(str, '\n');
        if (find)
        {
            *find = '\0';
        }
        else
        {
            while (getchar() != '\n')
            {
                continue;
            }
        }
    }
}
char showmenu(void);
void eatline(void); //读取到行末尾
void show(void (*fp)(char *), char *str);
void ToUpper(char *);   //把字符串转换成大写
void ToLower(char *);   //把字符串转换成小写
void Transpose(char *); //大小写转制
void Dummy(char *);     //不更改字符串
